package com.vitaf.cash.app.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.vitaf.cash.app.R
import com.vitaf.cash.app.common.VitafComDlog
import com.vitaf.cash.app.databinding.VitafDlogStepWalletDeleteBinding
import com.vitaf.cash.app.event.VitafEventPointType
import com.vitaf.cash.app.utils.VitafImgLoader
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/21 13:45
 * @Annotation：绑卡删除dialog
 */
class VitafWalletDeleteDlog: VitafComDlog {
    private lateinit var binding: VitafDlogStepWalletDeleteBinding
    private var mCallback: IDialogCallback? = null

    override val pageName: String = "User_Wallet_Delete_Tips"

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        pageRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun createVitafContentView(): View {
        binding = VitafDlogStepWalletDeleteBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initializeVitafViews() {
    }

    override fun setupVitafEventListeners() {
        setOnClickListener(binding.walletAccountDeleteCancel)
        setOnClickListener(binding.walletAccountDeleteConfirm)
        setOnClickListener(binding.imageWalletAccountDeleteClose)//关闭
    }

    override fun loadVitafData() {
    }

    override fun onVitafEventViewClick(v: View?) {
        dismiss()
        when(v?.id){
            R.id.walletAccountDeleteCancel -> {
                addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_CLICK.USER_WALLET_DELETE_TIPS_CANCEL,pageRemark)
            }
            R.id.walletAccountDeleteConfirm -> {
                addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_CLICK.USER_WALLET_DELETE_TIPS_CONFIRM,pageRemark)
            }
        }
        if(mCallback != null){
            mCallback?.onClick(v)
        }
    }

    /**
     * 设置需要删除的账户信息
     */
    @SuppressLint("SetTextI18n")
    fun showGombeCreditWalletInfo(info: JSONObject){
        VitafImgLoader.instance?.loadImageUrl(context,binding.walletTypeLogo,info.optString("walletLogo"), R.mipmap.gombe_credit_image_holder)
        binding.walletTypeTitle.text = info.optString("walletDesc")
        binding.walletAccountMobile.text = "+" + info.optString("walletMobile")

        if (info.optString("walletDesc").uppercase().startsWith("W")){
            binding.itemLayout.shapeDrawableBuilder
                .setSolidColor(getColor(R.color.gombe_credit_FFF1FCFF))
                .setStrokeColor(getColor(R.color.gombe_credit_FFDCF7FF))
                .intoBackground()
        } else {
            binding.itemLayout.shapeDrawableBuilder
                .setSolidColor(getColor(R.color.gombe_credit_FFFFF6F1))
                .setStrokeColor(getColor(R.color.gombe_credit_FFFFE9DC))
                .intoBackground()
        }
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }
}